package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.ExpensesDetail;
import com.example.mapper.ExpensesDetailMapper;
import com.example.service.ExpensesDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2023/12/27 20:35
 * @Version 1.0.0
 */
@Service
public class ExpensesDetailServiceImpl extends ServiceImpl<ExpensesDetailMapper, ExpensesDetail> implements ExpensesDetailService {

    @Autowired
    private ExpensesDetailMapper expensesDetailMapper;


    @Override
    public void saveBatch(List<ExpensesDetail> list) {
        for (ExpensesDetail expensesDetail : list) {
            expensesDetailMapper.insert(expensesDetail);
        }
    }

    @Override
    public void saveDetail(ExpensesDetail detail) {
        expensesDetailMapper.insert(detail);
    }

    @Override
    public List<ExpensesDetail> getDetailsById(Integer expenseId) {
        LambdaQueryWrapper<ExpensesDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ExpensesDetail::getExpenseId,expenseId);
        List<ExpensesDetail> expensesDetails = expensesDetailMapper.selectList(lambdaQueryWrapper);
        return expensesDetails;
    }

    @Override
    public void deleteByExpenseId(Integer expenseId) {
        LambdaQueryWrapper<ExpensesDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ExpensesDetail::getExpenseId,expenseId);
        expensesDetailMapper.delete(lambdaQueryWrapper);
    }
}
